Skip to content

Conversation

@soburi
Copy link
Member

@soburi soburi commented Feb 1, 2026

This PR introduce new configuration system without variants/[board].overlay.

Boards that has arduino like connector mostly has define arduino-header.
We can use this information to configure automatically for each boards.
We can support all zephyr supported that has arduino-header.
That means, we make it works for more 200 boards, including Nucleo series.

However, only Blinky works out of the box, and ADC and PWM channels are required.
These should be made into snippets in the future.

@soburi soburi force-pushed the configure_by_connector_def branch from 30e80c9 to 2157ae2 Compare February 1, 2026 15:38
@soburi soburi changed the title Configure by connector def Support **file-less** configuration Feb 1, 2026
@soburi soburi changed the title Support **file-less** configuration Support "file-less" configuration Feb 1, 2026
@soburi soburi force-pushed the configure_by_connector_def branch 2 times, most recently from d14bab2 to 769f878 Compare February 5, 2026 15:17
@soburi soburi marked this pull request as ready for review February 5, 2026 15:17
Copilot AI review requested due to automatic review settings February 5, 2026 15:17
@soburi soburi marked this pull request as draft February 5, 2026 15:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a "file-less" configuration system that automatically configures boards using Arduino-compatible header definitions from the device tree, eliminating the need for board-specific overlay files. The system detects supported connector types (arduino_header, arduino_mkr_header, etc.) and automatically maps GPIO pins, enabling support for 200+ Zephyr-supported boards including the Nucleo series.

Changes:

  • Added automatic board detection using device tree connector labels (arduino_header, pico_header, etc.)
  • Introduced GPIO port/pin abstraction layer with constexpr helper functions for compile-time pin mapping
  • Modified tone/noTone implementation to support dynamic timer allocation by tracking pin assignments
  • Updated PWM and ADC pin mappings to support both legacy and new connector-based configurations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 21 comments.

File Description
cores/arduino/Arduino.h Adds macro definitions for automatic connector detection (ZARD_CONNECTOR, ZARD_ADC_CONNECTOR, ZARD_PWM_CONNECTOR) and updates digital/analog pin enums to support both legacy and connector-based configurations
cores/arduino/zephyrCommon.cpp Implements GPIO abstraction layer with constexpr functions for pin mapping, updates all GPIO operations to use new abstraction, and modifies tone/noTone for improved timer management

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi force-pushed the configure_by_connector_def branch 3 times, most recently from 9d23221 to 293076c Compare February 9, 2026 10:57
@DhruvaG2000
Copy link
Member

This PR looks quite interesting, will be on my next list of things to review!

@soburi soburi force-pushed the configure_by_connector_def branch from 293076c to 7e1fd4c Compare February 9, 2026 14:23
* Copyright (c) 2026 TOKITA Hiroshi
*
* SPDX-License-Identifier: Apache-2.0
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can get #161 merged before this, then this will no longer be needed.

@soburi soburi force-pushed the configure_by_connector_def branch 5 times, most recently from d652dbd to 2444ff6 Compare February 10, 2026 22:51
A new configuration method has been adopted, allowing support to be added
with less configuration than before.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the configure_by_connector_def branch 2 times, most recently from b3744ae to 0dbaf95 Compare February 10, 2026 23:54
In preparation for improvements to allow the use of GPIOs without
device tree definitions,
the interface will be changed to specify port and pin instead of
`gpio_dt_spec`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
If digital-gpio-pins is not defined,
the pin configuration will be generated using the connector definition.

This allows ArduinoCore-Zephyr to be used on boards that have
arduino-header defined,
without requiring specific configuration in ArduinoCore-Zephyr.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

())

const struct adc_dt_spec arduino_adc[] = {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arduino_adc is enabled by checking adc_pin_gpios, but the array itself is generated from /zephyr,user/io-channels. This will fail to compile when adc-pin-gpios exists without io-channels, and it also prevents using io-channels unless adc-pin-gpios is present. Guard the array generation based on io_channels (provisioning) and keep association (adc_pin_gpios / connector map) independent.

Suggested change
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)

Copilot uses AI. Check for mistakes.
Comment on lines +666 to 670
pcb = find_gpio_port_callback(port);
__ASSERT(pcb != nullptr, "gpio_port_callback not found");

pcb->pins |= BIT(arduino_pins[pinNumber].pin);
pcb->pins |= BIT(local_gpio_pin(pinNumber));
setInterruptHandler(pinNumber, callback);
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attachInterrupt() can end up with port == nullptr from local_gpio_port(pinNumber) (invalid/unmapped global pin). In that case pcb will be nullptr and the __ASSERT(pcb != nullptr, ...) hard-fails; additionally BIT(local_gpio_pin(pinNumber)) is unsafe if the pin is invalid/out of range. Add an early return when port == nullptr (and validate the computed local pin before using it).

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +86
#if DT_NODE_EXISTS(DT_NODELABEL(arduino_header))
#define ZARD_CONNECTOR arduino_header

#define ZARD_ARDUINO_HEADER_R3_DIGITAL_MAP_0 D16
#define ZARD_ARDUINO_HEADER_R3_DIGITAL_MAP_1 D17
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connector fallback uses ZARD_CONNECTOR_PIN_NAME() which expands to ZARD_<COMPAT>_DIGITAL_MAP_<n> macros. Only the arduino_header compatible has these _DIGITAL_MAP_ macros defined here; if a board uses arduino_mkr_header / arduino_nano_header / pico_header / boosterpack_header without /zephyr,user/digital-pin-gpios, this will expand to undefined tokens and fail to compile. Either restrict the auto-connector path to compatibles you fully map, or add the missing mapping macros for those connector compatibles.

Copilot uses AI. Check for mistakes.
Comment on lines +140 to +144
#define ZARD_GET_NGPIOS(i, ...) DT_PROP(GET_ARG_N(UTIL_INC(i), __VA_ARGS__), ngpios)
#define ZARD_SUM_NGPIOS(...) \
LISTIFY(NUM_VA_ARGS(__VA_ARGS__), ZARD_GET_NGPIOS, (+), __VA_ARGS__)

#define ZARD_GLOBAL_GPIO_OFFSET_(ph) \
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZARD_GET_NGPIOS uses DT_PROP(..., ngpios) but the runtime global-pin mapping in zephyrCommon.cpp uses DT_PROP_OR(..., ngpios, 0). To keep the compile-time pin constants consistent with runtime behavior (and avoid a hard build failure if any GPIO controller node lacks ngpios), consider switching this to DT_PROP_OR(..., ngpios, 0) as well.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants